home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_s / startrek.zip / CHAPTER.005 next >
Text File  |  1989-05-15  |  43KB  |  991 lines

  1.         Chapter 5 page 1 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  2.  
  3.  
  4.                                     CHAPTER 5 
  5.  
  6.         5.1  Using the Sub-systems
  7.  
  8.              Before  any of the sub-systems can be used they must  be  in 
  9.         working  order.  Thus the state of each on-board sub-systems  has 
  10.         to  be  stored and tested before any sub-system is  used.    This 
  11.         task is performed by the Damage Control subroutine.
  12.  
  13.         5.2  Damage control
  14.  
  15.              The  damage  control  section is an important  part  of  the 
  16.         Starship.   It  keeps  track of the state of repair  of  all  the 
  17.         subsystems and allows the player to activate that system only  if 
  18.         it  is  working order.  Thus for example, the player  cannot  use 
  19.         Phasers  to  shoot  at the enemy if the Phaser  Banks  have  been 
  20.         damaged.
  21.  
  22.              The  state of the subsystems are stored in an array  labeled 
  23.         D(I) such that 
  24.  
  25.         D(0) =  the state of the            Engines (Navigation)
  26.         D(1) =  the state of the            Short Range Sensors
  27.         D(2) =  the state of the            Long Range Sensors
  28.         D(3) =  the state of the            Phasers
  29.         D(4) =  the state of the            Photon Torpedoes
  30.         D(5) =  the state of the            Computer
  31.         D(6) =  the state of the            Shields
  32.         etc.
  33.  
  34.              Gaining  access  to the state of any sub-system  is  then  a 
  35.         matter  of accessing the appropriate element in the  array.   For 
  36.         example, if the state of the Phaser Banks is required, looking at 
  37.         the  contents of the fourth element of the array counting from  0 
  38.         or D(3) will tell us how they are.
  39.  
  40.              A  damage  control  status display shows the  state  of  any 
  41.         damaged sub-system by displaying its name and the estimated  time 
  42.         for  repairs  to  be completed (ETR) as shown  in  the  following 
  43.         typical display.
  44.  
  45.         DAMAGE CONTROL AT QUADRANT 4,6
  46.         SYSTEM                     ETR
  47.         LONG RANGE SENSORS          1
  48.         PHASERS                     2
  49.         HOW MANY DAYS TO SPEND ON REPAIRS SIR ?
  50.  
  51.              The state of the Long Range Sensors and the Phaser banks are 
  52.         shown  together  with their estimated time  to  complete  repairs 
  53.         (ETR).  The player is also asked to allocate time to perform  the 
  54.         repairs.  If the player chooses not to wait for the repairs to be 
  55.         performed,  but move around and take the chance of fighting  only 
  56.         armed  with torpedoes, zero time can be entered as a response  to 
  57.         the question.
  58.  
  59.  
  60.  
  61.         Copyright (c) Joe Kasser 1989
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         Chapter 5 page 2 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  68.  
  69.  
  70.              If the ETR is stored in the elements of the array  directly, 
  71.         then examining the contents of any element will tell us how  long 
  72.         it will take for the sub-system to be repaired.  For example,  if 
  73.         the  value stored in D(4) is 2 then the ETR for the Phaser  Banks 
  74.         is between 1 and 2 stardates.
  75.  
  76.              If the value stored in the element is 0 then that sub-system 
  77.         is  in  working order.  Conversely any  sub-system  containing  a 
  78.         value  greater than 0 in the D(I) array, is damaged.  Using  this 
  79.         principle we can display the state of the sub-systems, fix any of 
  80.         them  by  setting  the contents of the element  to  0  or  damage 
  81.         something by setting the contents of the particular element to  a 
  82.         positive value.  
  83.  
  84.              The flow chart for the damage control subroutine is shown in 
  85.         figure 5.1.  The procedure begins by displaying the heading.    A 
  86.         loop  is then performed to identify if any sub-system is  damaged  
  87.         (ie, check if the value stored in the D(I) matrix is greater than 
  88.         zero.   If  none  of the sub-systems are damaged,  a  message  is 
  89.         displayed accordingly.  If at least one is damaged, the estimated 
  90.         time  to repair stored in the array associated with  the  damaged 
  91.         sub-system  is  displayed.   Repairs are in  order  only  if  the 
  92.         condition  is  not  Red, namely, there are  no  Klingons  in  the 
  93.         Quadrant.  If this condition is true, the repair time  allocation 
  94.         is requested and the repairs carried out.  If anything is  fixed, 
  95.         that happening  is displayed.  Finally the time remaining in  the 
  96.         game is adjusted to cover the time that has passed performing the 
  97.         repairs.
  98.  
  99.              The  technique used to display the state of the contents  of 
  100.         the  D(I) array is to sample the contents of each element of  the 
  101.         array in turn and test to see if it equal to 0.  If it is greater 
  102.         than  0,  damage  is  present.    The  BASIC  statement  to  test 
  103.         something is the IF statement.  The state of the contents of each 
  104.         element in turn can be tested by a set of statements such as 
  105.         IF  D(I) = 0 THEN
  106.  
  107.         A set of such statements where I = 0, in the first one, I = 1  in 
  108.         the second one can be used as follows
  109.  
  110.         2801  IF D(0) = 0 THEN 2821
  111.         2811  REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
  112.         2821  IF D(1) = 0 THEN 2841
  113.         2831  REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
  114.         2841  IF D(2) = 0 THEN 2861
  115.         2851  REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
  116.  
  117.         and  so  on  for  all the elements in  the  array.    This  is  a 
  118.         perfectly  valid section of a program but there is a better  way.   
  119.         We  know that there are up to C1 elements in the array (0, 1,  2, 
  120.         3, 4, 5, and so on).  Change the routine to read
  121.  
  122.         2801  LET I = 0
  123.         2811  IF D(I) = 0 THEN 2831
  124.         2821 REM SOMEHOW DISPLAY THE DAMAGE MESSAGE IN THIS LINE
  125.  
  126.  
  127.         Copyright (c) Joe Kasser 1989
  128.  
  129.  
  130.  
  131.  
  132.  
  133.         Chapter 5 page 3 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  134.  
  135.  
  136.         2831  LET I = I + 1
  137.         2841  IF I < C1 THEN 2811
  138.         2851  REM PROGRAM FLOW CONTINUES HERE AFTER THE LOOP
  139.  
  140.              While  this  technique  works,  it  puts  the  onus  on  the 
  141.         programmer  to  increment  the loop counter  (I)  for  each  pass 
  142.         through  the loop.  BASIC contains a built in loop  counter  that 
  143.         takes  care  of the loop counter.  Using the 'FOR/NEXT'  pair  of 
  144.         statements, the loop can be constructed as follows
  145.  
  146.         2801  FOR I = 0 TO C1 : REM TEST C1 ELEMENTS
  147.         2811  IF D(I) = 0 THEN 2831
  148.         2821  REM SOMEHOW DISPLAY THE DAMAGE MESSAGE IN THIS LINE
  149.         2831  NEXT
  150.         2841  REM PROGRAM FLOW CONTINUES HERE AFTER THE LOOP
  151.  
  152.         The  'FOR/NEXT'  construction thus may be used  to  simplifY  the 
  153.         construction of loops.
  154.  
  155.              BASIC also builds into the 'FOR/NEXT' loop the capability to 
  156.         advance the loop counter by more than one step per pass using the 
  157.         'STEP' statement.
  158.  
  159.         2801  FOR I = 0 TO C1 STEP 2 
  160.  
  161.         will  for example loop using values of I equal to 0, 2, 4  and  6 
  162.         sequentially, and will skip values of I equal to 1, 3 and 5
  163.  
  164.              So far the discussions have not considered how the state  of 
  165.         the  sub-system  is displayed.   The technique used  here  is  to 
  166.         store  the names of each sub-system in a String Array,  D$(I)  in 
  167.         the  same order as the D(I) array that contains the state of  the 
  168.         system.
  169.  
  170.              Lines  4570/4590  set  up the names of  each  of  the  C1-C2 
  171.         subsystems that can be damaged in an array containing C1 elements 
  172.         labeled  D$(I)  which happens to be a part of the array  used  to 
  173.         store the C1 command function names, such that 
  174.  
  175.         D$(0) = "WARP ENGINES"
  176.         D$(1) = "SHORT RANGE SENSORS"
  177.         D$(2) = "LONG RANGE SENSORS"
  178.         D$(3) = "PHASER BANKS"
  179.         D$(4) = "PHOTON TORPEDO TUBES"
  180.         D$(5) = "MAP (COMPUTER)"
  181.         D$(6) = "SHIELDS"
  182.         ETC.
  183.  
  184.              Now the BASIC statement to display something at the terminal 
  185.         is  PRINT.  Thus PRINT D$(I) would print the name stored  in  the 
  186.         D$(I) array for the corresponding value of I.  For example if you 
  187.         wanted  all the names to be listed, you could type the  following 
  188.         routine into the existing game program in the computer.
  189.  
  190.  
  191.  
  192.  
  193.         Copyright (c) Joe Kasser 1989
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         Chapter 5 page 4 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  200.  
  201.  
  202.  
  203.         2811  REM DEMO LOOP
  204.         2821  FOR I = 0 TO C1
  205.         2831  PRINT D$(I)
  206.         2841  NEXT
  207.         2851  RETURN
  208.  
  209.              If  you  now type in the word RUN you tell the  computer  to 
  210.         execute your program.  When you get the 'COMMAND ?' prompt, enter 
  211.         the  word  'DAM'  to initiate the Damage  Control  command.   The 
  212.         resultant listing would be as follows
  213.  
  214.         WARP ENGINES
  215.         SHORT RANGE SENSORS
  216.         LONG RANGE SENSORS
  217.         PHASERS
  218.         PHOTON TORPEDOES
  219.         COMPUTER
  220.         SHIELDS
  221.         LONG RANGE PROBES
  222.         TRANSPORTER
  223.         SHUTTLECRAFT
  224.         DAMAGE CONTROL
  225.         VISUAL
  226.         RESIGN
  227.         SAVE THE STATE OF THE GAME
  228.         LOAD A SAVED GAME
  229.  
  230.         COMMAND ?
  231.  
  232.              At  this time hold down the 'CNTRL' (Control) key  with  one 
  233.         finger  and  touch  the 'C' key with the other.   You  have  just 
  234.         interrupted  the program in mid-flow by typing in  the  Control-C 
  235.         character  also  written  as ^C.  The computer  should  give  you 
  236.         message saying that a BREAK occurred.
  237.  
  238.              In  our instance we want to print out the name of  the  sub-
  239.         system and its estimated repair time, namely two things.    BASIC 
  240.         allows  that  by  the  use of the comma  (,)  or  semi-colon  (;) 
  241.         separators.  For example the statements
  242.  
  243.         2831  PRINT D$(I),D(I) 
  244.         and
  245.         2831  PRINT D$(I);D(I) 
  246.  
  247.         do not perform the same operation.
  248.  
  249.              The  semi-colon displays the second (or subsequent) item  to 
  250.         be  displayed immediately  following the previous one, while  the 
  251.         comma performs a tab function which moves the printhead or cursor 
  252.         over to the next tab position just as an electric typewriter.
  253.  
  254.              So from before, the FOR/NEXT routine to display the names of 
  255.         the  sub-systems  and  their  repair  times  would  thus  require 
  256.         changing line 2831 to 
  257.  
  258.  
  259.         Copyright (c) Joe Kasser 1989
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         Chapter 5 page 5 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  266.  
  267.  
  268.  
  269.         2831  PRINT D$(I),D(I)
  270.  
  271.              Again type RUN (carriage return). When you get the  'COMMAND 
  272.         ?' prompt, try the 'DAM' command. The resultant listing will  not 
  273.         be  perfectly  formatted.  Try it and see.  The reason  that  the 
  274.         display  is not formatted properly is because the lengths of  the 
  275.         names of the sub-systems are different.  The built in tab feature 
  276.         in BASIC will only tab across to the next tab position.
  277.  
  278.              You can set your own tab position anywhere along the line by 
  279.         using the TAB statement. If line 2831 is changed to
  280.  
  281.         2831  PRINT D$(I) ; TAB(28) ; D(I)
  282.  
  283.         the  result will be formatted correctly. Break the program  (^C), 
  284.         change line 2831 and try it.
  285.  
  286.  
  287.              The  flow  chart  for the  DAMAGE.CONTROL  function  may  be 
  288.         implemented in BASIC as shown in figure 5.2.
  289.  
  290.              Consider  each  of the lines in turn, what they do  and  how 
  291.         they do it.  The damage control function begins at line 2800 with 
  292.         a REMark or comment statement telling you what function is  being 
  293.         performed.
  294.  
  295.              It  has already been mentioned that the most  commonly  used 
  296.         subroutines  are  placed towards the beginning  of  the  program.  
  297.         This  is  done  to  speed up execution  time,  since  most  BASIC 
  298.         interpreters  search for line numbers sequentially from the  top.  
  299.         When you enter a line of code into a program in the  interpretive 
  300.         mode, the interpreter finds the position for the line and inserts 
  301.         it in the correct place in the sequence of statements.
  302.  
  303.              The  Damage  Control  subroutine  begins  with  the   REMark 
  304.         statement in line 2800.  Line 2810 uses the subroutine at line 70 
  305.         to  display  the  name  of  the  function  being  performed.    A 
  306.         temporary  variable, D8 is then set to 0.  A loop in  lines  2820 
  307.         and  2830 tests the status of each of the subsystems that can  be 
  308.         damaged in the damage control or commands array D(I).  There  are 
  309.         C1  commands  but  only C1-C2 of them  can  be  damaged.   Damage 
  310.         control  cannot  be  damaged, that doesn't  make  sense.   Visual 
  311.         sensors  similarly  can't be damaged, and you can always  try  to 
  312.         resign.   The use of C1-C2 in line 2820 and later  lines,  allows 
  313.         the routine to work if further commands are added.  Adding a  new 
  314.         command  later  should  only  require  changes  in  the   command 
  315.         subroutine,  it should not require changes anywhere else  in  the 
  316.         program.  When you write programs keep them modular and make  the 
  317.         modules  stand-alone.   That means that changes in  one  function 
  318.         should not require changes in more than one module.  If you write 
  319.         code  that  requires modifications to many of  its  modules  when 
  320.         implementing  a  change  you  will spend an  awful  lot  of  time 
  321.         performing  de-bugging,  because  you will have to do  a  lot  of 
  322.         searching to find where the modifications have to be made.
  323.  
  324.  
  325.         Copyright (c) Joe Kasser 1989
  326.  
  327.  
  328.  
  329.  
  330.  
  331.         Chapter 5 page 6 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  332.  
  333.  
  334.  
  335.              If  the  value assigned to any sub-system in  the  array  is 
  336.         greater  than zero, ie. signifying that something is damaged  the 
  337.         value  of  D8 is incremented by one.   At this time, we  are  not 
  338.         looking  to see what is damaged, just if something is.   A  PRINT 
  339.         statement  is then executed to cause the display to  advance  one 
  340.         line  at  the console and the value of D8 is tested.   If  it  is 
  341.         equal to zero then nothing is damaged and a message is  displayed 
  342.         accordingly.  There is then no need to continue in the subroutine 
  343.         and the GOTO 2910 statement causes the program to branch  forward 
  344.         to line 2910 skipping the remainder of the subroutine.  The exact 
  345.         value of D8 is not important at this time.  It is however at this 
  346.         time, a count of how many of the sub-systems are damaged.
  347.  
  348.              The  damage control display begins at line 2840.  This  line 
  349.         displays  the heading.  The loop in lines 2850 and line 2860  now 
  350.         examine the state of each item in the array.  If any are damaged, 
  351.         that  fact is detected in line 2850 and a display of the name  of 
  352.         the  sub-system  and its estimated time to repair is  made.   The 
  353.         estimate  is  printed out as an approximate  number  as  follows.   
  354.         The statement used is
  355.  
  356.         PRINT INT(D(I)+Z).
  357.  
  358.         This  takes the value stored in the array, adds 1 to it and  then 
  359.         converts  the result to an integer.  this process is known as  in 
  360.         mathematics as "rounding up" to the next significant digit.   The 
  361.         process could have been written as 
  362.  
  363.         X = D(I) + Z : X = INT(X) : PRINT X
  364.  
  365.         which  would  do  the same job but require the use  of  an  extra 
  366.         (dummy)  variable 'X'.  The display is formatted by  the  TAB(28) 
  367.         statement.    After  the  state  of all  the  systems  have  been 
  368.         sampled,  the  presence  of  Klingons in  the  quadrant  is  then 
  369.         determined.  If the value of the variable K is greater than 0, at 
  370.         least  one Klingon is present in the quadrant (we don't care  how 
  371.         many at this time) and the subroutine ends at this time by  GOing 
  372.         TO line 2910.
  373.  
  374.              At  this  stage we have reached  line 2870.   There  are  no 
  375.         klingons  in the quadrant so the value assigned to K is zero.   A 
  376.         'PRINT' statement is executed and the computer then requests  the 
  377.         number  of  stardates to be spent on repairs, using  the  'INPUT' 
  378.         statement  and the prompt "HOW MANY DAYS TO SPEND ON REPAIRS  SIR 
  379.         ".   Note the space after the SIR.  This space separates the  SIR 
  380.         from  the ? that BASIC displays to inform the user that an  input 
  381.         is  being  requested.   The player's reply  is  assigned  to  the 
  382.         variable D8.  D8 is thus re-used at this time.
  383.  
  384.              Re-using variables is good practice because it saves memory, 
  385.         but  on  the  other hand, can lead to problems if  the  state  of 
  386.         variables  are  changed by different routines because it  may  be 
  387.         difficult  to  find  out where the change  is  being  made.   The 
  388.         player's  input is first checked to see if a negative number  was 
  389.  
  390.  
  391.         Copyright (c) Joe Kasser 1989
  392.  
  393.  
  394.  
  395.  
  396.  
  397.         Chapter 5 page 7 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  398.  
  399.  
  400.         input.  If it was, the value of D8 is set to zero.  After all  we 
  401.         cannot  allow  negative  time  in the  game.    The  repairs  are 
  402.         performed  in lines 2880 to 2900.  For each sub-system liable  to 
  403.         damage  a  test is performed.  If the  sub-system  is  undamaged, 
  404.         nothing  happens  to it and the program skips to line  2900.   If 
  405.         however it is damaged (the value assigned to D(I) > 0 ) then line 
  406.         2890  is performed.  The value assigned to D8 is subtracted  from 
  407.         the  number  stored in the array.  If the result is equal  to  or 
  408.         less  than  zero repairs have been completed and  the  sub-system 
  409.         should  be  in working order.  The value in  the  damage  control 
  410.         status  array  is then set to zero and a message  that  the  sub-
  411.         system  has been repaired is displayed at the console.  When  all 
  412.         is  said and done, line 2910 causes the subroutine to  RETURN  to 
  413.         the main program loop.
  414.  
  415.              The  DAM subroutine uses one nested subroutine  starting  at 
  416.         line 70 to format the headings on the various commanded displays.  
  417.         Line 70 contains the comment while the operation is performed  by 
  418.         line 80.  The name of the operation stored in the D$(I) array  is 
  419.         first  displayed,  followed  by the  words  'AT  QUADRANT'.   The 
  420.         computer counts the quadrants from 0 to 7, but the player  counts 
  421.         them  from 1 to 8.  The adjustment is performed by the  Q1+Z  and 
  422.         Q2+Z statements.  Take careful note of the formatting semi colons 
  423.         used in the line.  When this subroutine is called, the value of I 
  424.         has  been set up in the command matching loop of lines  3060/3070 
  425.         for the branch using the 'ON' statement in line 3080.
  426.  
  427.              At first glance it seems that this procedure is too complex.  
  428.         why  not just subtract the D8 from D(I) for each element  in  the 
  429.         array, and display a message for those having a result less  than 
  430.         zero.   Well why not?  the answer is a question. How do you  then 
  431.         detect the difference between systems in working order and  those 
  432.         that have just been repaired?
  433.  
  434.              Delete lines 2811 to 2851 by typing 'DELETE 2811-2851'  into 
  435.         the computer.  Notice the use of the 'DELETE' statement which can 
  436.         be  used to delete all or selected parts of a program.   Here  we 
  437.         just  deleted  the  temporary  lines we used  to  play  with  the 
  438.         formatting  of the Damage Control Status display.  The format  of 
  439.         the  command  is the same as that of the  'LIST'  command.   Some 
  440.         dialects of BASIC may require a slightly different way of  typing 
  441.         the  command (e.g. DELETE 2811,2851).  Add lines 70, 80 and  line 
  442.         2800  to 2910 (as listed in figure 5.2) to the program  and  save 
  443.         the  program.   Then RUN it.  The damage control  command  should 
  444.         work  as  should the "Help" command (Command 0).   Interrupt  the 
  445.         program flow with a ^C and dummy in some damage.  You do that  as 
  446.         follows.   Let  us  enter some damage to the  one  sub-system  by 
  447.         typing in
  448.  
  449.         D(3) = 4
  450.  
  451.         which sets the damage status of device 3 to 4 stardates estimated 
  452.         repair  time.   What we have done is interactively  entered  some 
  453.         data directly into a variable from the console.  It is a good way 
  454.         to  debug the program.  Now to continue the program just type  in 
  455.  
  456.  
  457.         Copyright (c) Joe Kasser 1989
  458.  
  459.  
  460.  
  461.  
  462.  
  463.         Chapter 5 page 8 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  464.  
  465.  
  466.         CONT.   Do not type RUN or the computer will reset all  variables 
  467.         to  zero  and  you will lose your input for  D(3).   If  you  now 
  468.         execute the Damage Control command you will get a notice that one 
  469.         sub-system  is  damaged.   Enter a repair time  allocation  of  2 
  470.         stardates,  and  try  the command again.  See  how  the  ETR  has 
  471.         changed.  Now enter a repair time of 5 days and see if you get  a 
  472.         "REPAIRED"  message.   You should.  You have  now  exercised  the 
  473.         damage  control  function  and are ready to go  onto  bigger  and 
  474.         better things.  
  475.  
  476.              The  next command to activate is the MAP (COMPUTER)  command 
  477.         so that we can take a look at how the galaxy was set up.
  478.  
  479.         5.3 The Map Display
  480.  
  481.              The map display is one of the Ship's computer functions.  It 
  482.         is directly accessible from the main command loop as well as from 
  483.         the  computer. It shows the contents of all the quadrants in  the 
  484.         galaxy  that  have  been scanned by Long  Range  or  Short  Range 
  485.         sensors or by Long Range Probes as a three digit number with  the 
  486.         following convention.
  487.  
  488.         The 100's digit     = number of Klingons
  489.         the  10's digit     = number of Starbases
  490.         the   1's digit     = number of Stars,
  491.  
  492.              thus  for  example, 317 means that the quadrant  contains  3 
  493.         Klingons,  1 Starbase and 7 stars.  Quadrants that are  unscanned 
  494.         show up as "***" on the display.
  495.  
  496.              The  flow  chart to implement the MAP function is  shown  in 
  497.         figure 5.3.  The nested loops can be seen at a glance.  The  same 
  498.         nesting technique is used as in the initialization routine.   The 
  499.         routine first tests to see if the map function is damaged.  If it 
  500.         is,  a  message  is displayed stating that fact, if  not,  it  is 
  501.         assumed  to be in working order and a map display  is  generated.  
  502.         The  map  displays  the contents of each  of  the  quadrants  and 
  503.         emphasizes  the  quadrant  containing the  Enterprise.   In  this 
  504.         version  of  the game, that emphasis is to display  the  quadrant 
  505.         containing the Enterprise surrounded by '+' signs.  A sample  map 
  506.         display is shown below.
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.         Copyright (c) Joe Kasser 1989
  524.  
  525.  
  526.  
  527.  
  528.  
  529.         Chapter 5 page 9 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  530.  
  531.  
  532.         MAP FOR QUADRANT 4,6
  533.  
  534.               1     2     3     4     5     6     7     8
  535.         1    ***   ***   ***   ***   ***   ***   ***   ***
  536.         2    ***   ***   ***   ***   ***   ***   ***   ***
  537.         3    ***   ***   ***   ***   ***   ***   ***   ***
  538.         4    ***   ***   ***   001   012   104   ***   ***
  539.         5    ***   ***   ***   002  +206+  307   ***   ***
  540.         6    ***   ***   ***   717   001   003   ***   ***
  541.         7    ***   ***   ***   ***   ***   ***   ***   ***
  542.         8    ***   ***   ***   ***   ***   ***   ***   ***
  543.  
  544.              The map display function can be written in BASIC as shown in 
  545.         figure  5.4.   The  sequence begins at line 200  with  the  usual 
  546.         REMark statement. Then line 210 tests the state of repair of  the 
  547.         MAP/COMPUTER.  If it is in working order namely if D(I) = 0  then 
  548.         the  program flows on to line 220 skipping over the rest of  line 
  549.         210  which displays a message stating that the device is  damaged 
  550.         and  causes the subroutine to exit via line 280.  Line 210  could 
  551.         alternatively be written using the IF/ELSE construct as
  552.  
  553.         210 I=5 : IF D(I)=0 THEN 220 ELSE PRINT D$(I); "DOWN AT THIS TIME" : GOTO 280
  554.  
  555.         this  version of line 210 needs a dialect of BASIC that not  only 
  556.         recognizes  the IF/ELSE construct, but also branches to the  next 
  557.         subsequent  line number if the test fails. Which version is  used 
  558.         basically  depends on the programmer.  They all perform the  same 
  559.         operation.   The implementation of the IF/ELSE-THEN statement  in 
  560.         BASIC  may differ from version to version and tends to cause  the 
  561.         most problems when converting programs.
  562.  
  563.         5.4  LONG RANGE SENSORS 
  564.  
  565.              Long  Range  sensors show the contents  of  the  neighboring 
  566.         quadrants  but  in minimal detail.  An example of  a  long  range 
  567.         sensor scan is shown below;
  568.  
  569.         LONG RANGE SENSORS FOR QUADRANT 4,6
  570.  
  571.              001 012 104
  572.              002 206 317
  573.              717 001 003
  574.  
  575.         The Enterprise is located in the quadrant shown in the center  of 
  576.         the  display.  The contents of each quadrant are described  as  a 
  577.         three digit number with the following convention.
  578.  
  579.         The 100's digit     = number of Klingons
  580.         the  10's digit     = number of Starbases
  581.         the   1's digit     = number of Stars,
  582.  
  583.              thus  for  example, 317 means that the quadrant  contains  3 
  584.         Klingons, 1 Starbase and 7 stars.  Quadrants that are outside the 
  585.         galaxy show up as "***" on the display.
  586.  
  587.  
  588.  
  589.         Copyright (c) Joe Kasser 1989
  590.  
  591.  
  592.  
  593.  
  594.  
  595.         Chapter 5 page 10 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  596.  
  597.  
  598.              The  display  shows  a small section  of  space  around  the 
  599.         quadrant  that the Enterprise is located in, in a similar  format 
  600.         to  that  of the Map display.   This means that  the  display  is 
  601.         relative  to the position of the Enterprise.   The Enterprise  is 
  602.         always located in the center quadrant.
  603.  
  604.              The  flow  chart for the procedure is shown in  figure  5.5.  
  605.         The routine begins with a test to see if the sensors are damaged.  
  606.         If they are a message to that effect is displayed at the  console 
  607.         and  the subroutine skips everything else.  If they are not,  the 
  608.         standard  sensor subsystem heading is displayed and the loops  to 
  609.         perform the actual display functions begun.
  610.  
  611.              The  loop  counters each contain three iterations  of  their 
  612.         respective  loops.   This sensor display shows  the  contents  of 
  613.         space with the co-ordinates of the Enterprise as the center.  The 
  614.         row  display is thus with respect to Q1, the column display  with 
  615.         respect  to Q2.  The inside loop scans the quadrants in  adjacent 
  616.         columns  to  the  Enterprise, the outside loop  adjusts  the  row 
  617.         counter  so that the operation is performed on adjacent  rows  as 
  618.         well.   The quadrant containing the Enterprise is  also  scanned. 
  619.         Thus for each quadrant in the loop, a test is first performed  to 
  620.         determine if the quadrant is inside the galaxy.  If the  quadrant 
  621.         is inside the galaxy, and if the computer/map is not damaged, the 
  622.         map  array  is updated.  The contents of the  quadrant  are  then 
  623.         displayed  at  the  console  irrespective of  the  state  of  the 
  624.         computer.   As  long as the Long Range Sensors are  working,  the 
  625.         player will always get a scan display.  The map however will only 
  626.         be updated, if the ship's computer is also up.
  627.  
  628.              If  the  quadrant being scanned is outside the  galaxy,  the 
  629.         display will be "***".  The cursor is moved over one character by 
  630.         displaying  a "space" character, and the loop continues with  the 
  631.         next  quadrant in the row.  When the row has been scanned by  the 
  632.         inner  loop, the outer loop advances its loop counter to  perform 
  633.         the  operation  on  the next row.  Since the next row  is  to  be 
  634.         displayed on the next line the cursor is advanced to the start of 
  635.         the  next  line before the next set of quadrants  are  displayed.  
  636.         When the contents of all nine quadrants have been displayed,  the 
  637.         subroutine terminates.
  638.  
  639.              The BASIC language implementation of the flow chart is shown 
  640.         in figure 5.6.
  641.  
  642.              The  routine  starts at line 300 with a REMark  or  comment.  
  643.         Line 310 checks to see if the sensors are working (ie. if D(I)  > 
  644.         0  ).  If they are working, the 'IF' test fails and  the  program 
  645.         continues  on  line  320.   If  they  are  damaged,  the  program 
  646.         continues along line 310, displaying a "DAMAGED" message and then 
  647.         branching forward to the RETURN statement in line 370.  You  will 
  648.         see  many instances in many published programs where line 310  or 
  649.         its  equivalent will contain a 'RETURN' statement instead of  the 
  650.         'GOTO  the line which terminates the subroutine'.   Both  execute 
  651.         correctly,   however  it   good  practice  to  ensure  that   any 
  652.         subroutine has only one exit point.  It will make debugging a lot 
  653.  
  654.  
  655.         Copyright (c) Joe Kasser 1989
  656.  
  657.  
  658.  
  659.  
  660.  
  661.         Chapter 5 page 11 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  662.  
  663.  
  664.         simpler.
  665.  
  666.              Line 320 uses the subroutine beginning at line 70 to display 
  667.         the heading for the sensor scan display, and then proceeds to set 
  668.         up  the  loops for the row and column displays.  The  Long  Range 
  669.         Sensor display uses the same format as the Map display.  The  map 
  670.         displayed the whole galaxy, but here in the Long Range Sensors we 
  671.         only  want to see what is in the adjacent quadrants.   Namely  we 
  672.         want  to  look  at quadrants on each  side  of  the  Enterprise's 
  673.         location.   Since the Enterprise is located at quadrant Q1,Q2  at 
  674.         any  time,  our  loop  range must  be  the  co-ordinates  of  the 
  675.         Enterprise plus or minus one.  Thus the program statement
  676.         FOR I = Q1 - Z TO Q1 + Z : FOR J = Q2 - Z TO Q2 + Z.
  677.         The  PRINT  "  "; part of line 320 advances  the  cursor  between 
  678.         quadrant displays on the same line.
  679.  
  680.              Line  330  tests  to see if the quadrant  being  scanned  is 
  681.         outside  the  galaxy.  Quadrants within the galaxy  are  numbered 
  682.         from 0 to 7.  Thus any quadrant with a row or a column number  of 
  683.         less than 0 ( <0 ) or greater than 7 ( >7 ) is out of the  galaxy 
  684.         by  definition.   The display for those quadrants   is  always  a 
  685.         "***".  The program flow then jumps forward to NEXT statement  in 
  686.         line  360.  If the quadrant being scanned is inside  the  galaxy, 
  687.         line 340 tests the state of repair of the map/computer.  If it is 
  688.         up,  the  quadrant  scanned is entered into  the  computer.   The 
  689.         quadrant  is  scanned using the ABS(X) function.   This  function 
  690.         converts  a  number to its absolute or positive  value.   Thus  a 
  691.         positive  value remains a positive value, while a negative  value 
  692.         is  changed  to  a positive one.  We thus  don't  care  what  the 
  693.         previous state of the quadrant was before being scanned.
  694.  
  695.              Lines  350, 360 and 370 perform the same functions  as  line 
  696.         most  of line 250, lines 260, 270 and 280 respectively.   If  you 
  697.         want  to save memory space you could delete lines 350 to 370  and 
  698.         replace them by
  699.                                   350 GOTO 270
  700.         If  you do this, you will also have to change the  references  to 
  701.         those line numbers in lines 310 and 330.  For example in line 330 
  702.         you  will have to change the 360 to 250.  Since comprehension  of 
  703.         the  program is easier if lines 350 to 370 are used, the  program 
  704.         has been written using them.  Feel free to make the change if you 
  705.         want  to.   You  will  also change  the  format  of  the  display 
  706.         slightly.  Try it later on, and keep the version you like better
  707.  
  708.              Carefully  copy  line 300 to 370 into your  program.   Debug 
  709.         them  as  follows.  First RUN the program.      Perform  the  MAP 
  710.         command.   You should get the same unscanned display  as  before.  
  711.         If the whole map shows up scanned, you forgot to delete line 211.  
  712.         In that case, break the program and do it now. ReRUN the program.  
  713.         Now  do a Long Range Sensor command (LRS).  You should  then  see 
  714.         the  normal  long  range sensor display.   Then  repeat  the  map 
  715.         command,  and the quadrants that were scanned by the  long  range 
  716.         sensors should show up scanned on the map.
  717.  
  718.              It  is  then  time to break the program  (^C).   Damage  the 
  719.  
  720.  
  721.         Copyright (c) Joe Kasser 1989
  722.  
  723.  
  724.  
  725.  
  726.  
  727.         Chapter 5 page 12 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  728.  
  729.  
  730.         computer which will in effect damage the map by entering
  731.                                     D(5) = 3.
  732.         CONTinue  the program and try the 'MAP' command.  It won't  work.  
  733.         Try the 'LRS' or Long Range Sensor command.  Now use the 'DAM' or 
  734.         Damage  Control  command  to  fix the  map  and  request  another 
  735.         display.   The map should still be completely unscanned,  because 
  736.         the  computer (map) itself was damaged at the time that the  long 
  737.         range scan was performed.  Break the program again and damage the 
  738.         long range sensors by entering
  739.                                    D(2)  = 1.
  740.            CONTinue it and try the long range sensors again.  They  won't 
  741.         work.   Fix them and try the sensors followed by the  map  again.  
  742.         The sensors should work, and the map display should also  update.  
  743.         If  you like, break the program again and change the position  of 
  744.         the  Enterprise  by changing the values of Q1 and Q2.   when  you 
  745.         continue  the  program, the long range scan will  illuminate  and 
  746.         update a new section of the galaxy (if your new values for Q1 and 
  747.         Q2 were within the range of 0 and 7 inclusive).  If you made  any 
  748.         changes  to  the program during the  debugging  session,save  the 
  749.         program again at this point.
  750.  
  751.         5.5  Long Range Probes
  752.  
  753.              Long  Range Probes are a means to find out what lies  beyond 
  754.         the range of the Long Range Sensors without moving.  You can fire 
  755.         a probe in any direction just as you would fire a photon torpedo.  
  756.         The  probe speeds away at about Warp Factor 10, as such it  takes 
  757.         about 0.1 stardates to cross a quadrant.
  758.  
  759.              The  probe sends back a status report in the same format  as 
  760.         the  long range sensor/map data, as it enters each new  quadrant.  
  761.         The data received from the probe is automatically placed into the 
  762.         computer,  if  the computer is up at the time that  the  data  is 
  763.         received.  The communications technology used by the probes  give 
  764.         it  a  limited range however.  The signal grows too  weak  to  be 
  765.         received  when  the probe is about five quadrants away  from  the 
  766.         Enterprise.
  767.  
  768.              If the probe enters a quadrant containing Klingons there  is 
  769.         a  probability that they may detect and destroy it.   Should  you 
  770.         try and launch one when in a battle situation, the simulator will 
  771.         stop you.
  772.  
  773.         4300 REM LONG RANGE PROBE (LRP.ASC)
  774.         4310 IF D(I)>0 THEN PRINT "LAUNCH CONTROL INOPERATIVE AT THIS TIME" : GOTO 4470
  775.         4320 L3=L3+Z : IF L3>7 THEN PRINT " No Probes left...  Sir " : GOTO 4470
  776.         4330 IF K>0 THEN PRINT "You are not allowed to launch a probe during a battle" : GOTO 4470
  777.         4340 PRINT "LRP";L3;"Direction (1-9) "; : INPUT C : IF C=0 THEN 4470
  778.         4350 IF C<Z OR C>9 THEN 4340
  779.         4360 X1=Q1 : Y1=Q2 : X2=Q1+.5 :  Y2=Q2+.5 : T1=T : FOR I=0 TO E0 : T=T-.1
  780.         4370 Y=(C-Z)*.785398 : X=COS(Y) : Y=-SIN(Y)
  781.         4380 X2=X2+Y : Y2=Y2+X : X1=INT(X2) : Y1=INT(Y2)
  782.         4390 IF SQR((X1-Q1)^2+(Y1-Q2)^2)>5 THEN PRINT "Probe out of range" : GOTO  4460
  783.         4400 PRINT X1+Z;",";Y1+Z;" =";
  784.         4410 IF X1<0 OR X1>7 OR Y1<0 OR Y1>7 THEN PRINT "***" : GOTO 4450
  785.  
  786.  
  787.         Copyright (c) Joe Kasser 1989
  788.  
  789.  
  790.  
  791.  
  792.  
  793.         Chapter 5 page 13 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  794.  
  795.  
  796.         4420 E$=STR$(Q(X1,Y1)) : E$="00"+MID$(E$,2) : PRINT RIGHT$(E$,3) 
  797.         4430 IF D(5)=0 THEN Q(X1,Y1)=ABS(Q(X1,Y1))
  798.         4440 IF RND(Z)<ABS(Q(X1,Y1)+Z)/1000 THEN PRINT "Contact lost with probe" : GOTO 4460
  799.         4450 NEXT
  800.         4460 GOSUB 1800
  801.         4470 RETURN
  802.  
  803.         1800 REM SUBROUTINE FOR REPAIRS AFTER TIME (T1-T)
  804.         1810 IF T<0 THEN F9=4 : GOTO 1870
  805.         1820 N=0 :FOR I=0 TO C1-C2 : IF D(I)=<0 THEN 1860
  806.         1830 D(I)=D(I)-(T1-T) : IF D(I)>0 THEN 1860
  807.         1840 IF N=0 THEN PRINT : PRINT "DAMAGE CONTROL REPORTING " : N=Z
  808.         1850 D(I)=0 : PRINT D$(I);"REPAIRED" 
  809.         1860 NEXT
  810.         1870 RETURN
  811.  
  812.                 An  alternative  approach  to  implementing  Long   Range 
  813.         Sensors is to send them on their way and allow time to pass while 
  814.         they  report back.  If we assume that probes travel one  quadrant 
  815.         per  stardate we can set up a scenario in which the program  that 
  816.         implements the function is split into two sections, namely one to 
  817.         launch  the probes, and the other that deals with the  reporting.  
  818.         This  can  be somewhat (but not absolutely  true)  considered  as 
  819.         foreground  -  background programming, in which  the  probes  are 
  820.         launched in foreground, where the action is, while the  reporting 
  821.         is done in background as time goes by.
  822.  
  823.                 The  flowchart and code for the launching function  would 
  824.         be as shown below.
  825.  
  826.         : PROBELAUNCH
  827.         PROBES.DAMAGED =?
  828.              YES (1)   DISPLAY.MESSAGE
  829.              NO  (1)   PROBE.AVAILABLE =?
  830.                        YES  (2)  REQUEST.AND.ACCEPT.COURSE
  831.                                  LAUNCH.PROBE
  832.                                  KLINGONS.IN.QUADRANT =?
  833.                                  YES  (3)  DO.THEY.DETECT.PROBE =?
  834.                                            YES  (4)  PROBE.DESTROYED
  835.                                            THEN (4)
  836.                                  THEN (3)
  837.                        NO   (2)  DISPLAY."NONE.LEFT".MESSAGE
  838.                        THEN (2)
  839.              THEN (1) ;
  840.  
  841.         8005 REM LONG RANGE PROBE LAUNCH
  842.         8015 IF D(I)>0 THEN PRINT "LAUNCH CONTROL INOPERATIVE AT THIS TIME : GOTO 490
  843.         8025 FOR I = 0 TO 7 : IF L3(I)>0 THEN 8075
  844.         8035 INPUT "Course (1-8.99)";L4(I) : IF L4(I) = 0 THEN 8085
  845.         8045 IF L4(I)<Z OR L4(I)>8.99999 THEN 8035
  846.         8055 IF K>0 AND RND(Z)<K/7 THEN PRINT "Probe destroyed by the enemy" : L3(I) = 2 : GOTO 8085
  847.         8065 L1(I)=Q1 : L2(I)=Q2 : L6(I) = Q1+.5 : L7(I)=Q2+.5 : L3(I)=Z : L5(I)=T : PRINT "Probe";I+Z;"launched  Sir" : GOTO 8085
  848.         8075 NEXT : PRINT " No Probes left...  Sir "
  849.         8085 RETURN
  850.         8095 REM
  851.  
  852.  
  853.         Copyright (c) Joe Kasser 1989
  854.  
  855.  
  856.  
  857.  
  858.  
  859.         Chapter 5 page 14 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.         Copyright (c) Joe Kasser 1989
  920.  
  921.  
  922.  
  923.  
  924.  
  925.         Chapter 5 page 15 STARTREK THE COMPUTER PROGRAM By Joe Kasser
  926.  
  927.  
  928.                 The  flowchart and code for the reporting function  would 
  929.         be as shown below.
  930.  
  931.  
  932.         : PROBE.REPORTING
  933.         LOOP (max.number.of.probes)
  934.         +    PROBE.ACTIVE =?
  935.         +    YES  (1)  DAY.PASSED.SINCE.LAST.REPORT =?
  936.         +              PROBE.IN.RANGE =?
  937.  
  938.  
  939.         8105 REM LONG RANGE PROBE REPORTING
  940.         8115 FOR I = 0 TO 7
  941.         8125 IF L3(I) <> Z OR (L5(I) - T) < Z THEN 8235
  942.         8135 Y = (L4(I)-Z)*.785398 : X = COS(Y) : Y = -SIN(Y)
  943.         8145 L6(I) = L6(I) + Y : L7(I) = L7(I) + X : L1(I) = INT(L6(I)) : L2(I) = INT(L7(I))
  944.         8155 IF SQR((L1(I)-Q1)^2+(L2(I)-Q2)^2)>5 THEN 8225
  945.         8165 IF L8 = Z THEN 8205
  946.         8175 PRINT "LRP";I+Z;"reporting from Quadrant";L1(I)+Z;",";L2(I)+Z;"  =";
  947.         8185 IF L1(I)<0 OR L1(I)>7 OR L2(I)<0 OR L2(I)>7 THEN PRINT "***" : GOTO 8225
  948.         8195 E$ = STR$(Q(L1(I),L2(I))) : E$ = "00"+MID$(E$,2) : PRINT RIGHT$(E$,3) 
  949.         8205 IF D(5) = 0 THEN Q(L1(I),L2(I)) = ABS(Q(L1(I),L2(I)))
  950.         8215 IF RND(Z)<ABS(Q(L1(I),L2(I))+Z)/1000 THEN L3(I)=2 : IF L8=0 THEN  PRINT "Contact lost with probe"
  951.         8225 L5(I) = L5(I) - Z : IF L5(I)>T THEN 8125
  952.         8235 NEXT : RETURN
  953.         8305 REM LONG RANGE PROBE STATUS
  954.         8315 GOSUB 70 : PRINT "PROBE";" QUADRANT";"  SENSORS"
  955.         8325 FOR I = 0 TO 7 : PRINT I+Z;"   "; : IF L3(I) = 0 THEN PRINT "READY FOR LAUNCH " : GOTO 8405
  956.         8335 IF L3(I) = 2 THEN PRINT "DESTROYED" : GOTO 8405
  957.         8345 IF SQR((L1(I)-Q1)^2+(L2(I)-Q2)^2)>5 THEN PRINT "OUT OF RANGE" : GOTO 8405
  958.         8355 PRINT L1(I)+Z;",";L2(I)+Z;"  ";"    ";
  959.         8365 IF L1(I)<0 OR L1(I)>7 OR L2(I)<0 OR L2(I)>7 THEN PRINT "$$$"; : GOTO 8395
  960.         8375 E$ = STR$(Q(L1(I),L2(I))) : E$ = "00"+MID$(E$,2) : PRINT RIGHT$(E$,3) ;
  961.         8385 IF D(5) = 0 THEN Q(L1(I),L2(I)) = ABS(Q(L1(I),L2(I)))
  962.         8395 PRINT
  963.         8405 NEXT : RETURN
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.         Copyright (c) Joe Kasser 1989
  986.  
  987.  
  988.  
  989.  
  990.  
  991.